package com.niuniu.rushdorm.controller;

import com.niuniu.rushdorm.pojo.vo.UserVO;
import com.niuniu.rushdorm.pojo.vo.ResultVO;
import com.niuniu.rushdorm.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;

//    @PostMapping("/create")
//    public ResultVO createOrder(@RequestBody Map<String, Integer> requestMap, HttpServletRequest request) {
//        UserVO userVO = (UserVO) request.getAttribute("userVO");
//        Integer groupId = requestMap.get("group_id"), buildingId = requestMap.get("building_id");
//        Integer orderId = orderService.createOrder(userVO, groupId, buildingId);
//        return ResultVO.success(orderId);
//    }

    @GetMapping("/list")
    public ResultVO getOrderList(HttpServletRequest request) {
        UserVO userVO = (UserVO) request.getAttribute("userVO");
        Map<String, List<Map<String, Object>>> result = orderService.getOrderList(userVO);
        return ResultVO.success(result);
    }

    @GetMapping("/info")
    public ResultVO getOrderInfo(@RequestParam("order_id") Integer orderId) {
        Map<String, Object> result = orderService.getOrderInfo(orderId);
        return ResultVO.success(result);
    }
}
